<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>websocket client</title>
</head>

<body>
    <button id="open">open</button>
    <button id="send">send</button>
    <button id="close">close</button>
    <script type="text/javascript">
        (function () {

            let ws_8443 = null;

            // const URL_WEBSOCKET = 'wss://scanprinter.online:8443/ssldemo/websocket/8'
            // const URL_WEBSOCKET = 'wss://127.0.0.1:8888/websocket/8'
            // const URL_WEBSOCKET = 'wss://scanprinter.online:8443/scan-printer-1.0/websocket/8'
            // const URL_WEBSOCKET = 'ws://47.98.40.235/scan-printer-1.0/websocket/8'
            // const URL_HTTP = 'https://scanprinter.online/scan-printer-1.0'

            const URL_WEBSOCKET_8443 = 'wss://echo.websocket.org'
            // const URL_WEBSOCKET_8443 = 'wss://scanprinter.online:8443/sp/websocket/8'

            document.querySelector("#open").addEventListener('click', e => {

                ws_8443 = new WebSocket(URL_WEBSOCKET_8443);

                ws_8443.addEventListener('open', e => console.log('[8443] open event, %o', e));
                ws_8443.addEventListener('message', e => console.log('[8443] message event, %o', e));
                ws_8443.addEventListener('close', e => console.log('[8443] close event, %o', e));
                ws_8443.addEventListener('error', e => console.log('[8443] error event, %o', e));

            });

            document.querySelector("#send").addEventListener('click', e => {
                ws.send('hello');
            });

            document.querySelector("#close").addEventListener('click', e => {
                ws.close();
                ws = null;
            });
        })()
    </script>
</body>

</html>